﻿namespace ProjectEuler.Core.Helpers
{
    public class Triplet
    {
        public int A { get; set; }
        public int B { get; set; }
        public int C { get; set; }

        public bool IsPythagorean
        {
            get
            {
                return IsTripletPythagorean(A, B, C);
            }
        }

        public static bool IsTripletPythagorean(int a, int b, int c)
        {
            // some basic filtering to speed things up

            // Exactly one of a, b is divisible by 3.
            if ((a % 3 != 0) && (b % 3 != 0)) return false;
            // Exactly one of a, b is divisible by 4.
            if ((a % 4 != 0) && (b % 4 != 0)) return false;
            //Exactly one of a, b, c is divisible by 5.
            if ((a % 5 != 0) && (b % 5 != 0) && (c % 5 != 0)) return false;
            //Exactly one of a, b, (a + b), (b − a) is divisible by 7.
            if ((a % 7 != 0) && (b % 7 != 0) && ((a + b) % 7 != 0) && ((b - a) % 7 != 0)) return false;

            var ret = ((a < b) && (b < c));
            ret = ret && (((a * a) + (b * b)) == (c * c));
            return ret;
        }

        public Triplet(int a, int b, int c)
        {
            A = a;
            B = b;
            C = c;
        }

        public int Product
        {
            get
            {
                return A * B * C;
            }
        }

        public int Sum
        {
            get { return A + B + C; }
        }

        public new string ToString()
        {
            return "(" + A + ", " + B + ", " + C + ")";
        }
    }
}